﻿using System;
using System.Text;
using System.Web.Security;
using EmptyWallGallery.Core;
using EmptyWallGallery.Core.Utilities;

namespace EmptyWallGallery.FrontEnd
{
    public partial class Artists : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            BindData();

            Page.Title = "Artists - " + Configs.WebTitle;
            Page.MetaDescription = "Artists - " + Configs.WebDescription;
        }

        public void BindData()
        {
            lstAlbum.DataSource = Core.BLL.Album.Instance.GetAll();
            lstAlbum.DataBind();
        }

        protected string WriteAlbumImage(string albumId)
        {
            //<%# WriteImage(Eval("ImageUrl").ToString(), Convert.ToDateTime(Eval("ImageDate").ToString()), Eval("UserId").ToString())%>
            var objImage = new Core.BLL.Images().GetByAlbum(0, Convert.ToInt32(albumId), true);
            return objImage.Count == 0
                ? "<img src=\"/images/no_image_s.gif\" border=\"0\" class=\"noimg\" />"
                : WriteImage(objImage[0].ImageUrl, objImage[0].ImageDate, objImage[0].UserId);
        }

        protected string WriteImage(string fileName, DateTime createDate, string uploadBy)
        {
            var objUser = Membership.GetUser(Guid.Parse(uploadBy));
            if (objUser == null) return "";

            var strImageDefault = fileName == ""
                                      ? "/images/no_image_s.gif"
                                      : "/Uploads/" + objUser.UserName + "/" + createDate.Year + "/" +
                                        Common.Instance.Right("0" + createDate.Month, 2) + "/" +
                                        Common.Instance.Right("0" + createDate.Day, 2) + "/";

            return "<img src=\"" + strImageDefault + "500x0__" + fileName + "\" border=\"0\" />";
        }
    }
}